package com.gcsoftware.web.controller;

import com.gcsoftware.beans.LoginGroup;
import com.gcsoftware.beans.PageObj;
import com.gcsoftware.beans.SysLog;
import com.gcsoftware.web.mapper.db.LoginMapper;
import com.gcsoftware.web.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 管理页面
 * @author czp
 * date 2018-06-11
 */
@Controller
@RequestMapping("manage")
public class ManageController extends BaseController {
    @Autowired
    private LoginMapper loginMapper;

    @Autowired
    private LoginService loginService;

    /**
     * 登陆分组统计
     * @return 图表数据
     * curl http://localhost:8080/manage/loginGroupCount -X POST
     */
    @ResponseBody
    @RequestMapping(value = "/loginGroupCount", method = RequestMethod.POST)
    public List<LoginGroup> loginGroupCount() {
        return loginMapper.userLoginGroup();
    }

    /**
     * 获取登陆日志列表
     * @param loginAction 登陆动作
     * @param time 时间
     * @return 日志列表
     * curl http://localhost:8080/manage/getSysLogs -d ""
     */
    @ResponseBody
    @RequestMapping(value = "/getSysLogs", method = RequestMethod.POST)
    public PageObj<SysLog> getSysLogs(@RequestParam(value = "loginAction", required = false) String loginAction,
          @RequestParam(value = "time", required = false) String time,
          @RequestParam(value = "page") int page,
          @RequestParam(value = "rows") int rows,
          @RequestParam(value = "sord") String sord) {
        logger.info("page : " + page + " rows : " + rows + " sord : " + sord + " time : " + time + " loginAction : " + loginAction);
        return loginService.getSysLogs(loginAction, time, page, rows, sord);
    }
}
